package com.sh.personnel.security;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * 用户密码登录认证
 * @author 林思浩
 * @date 2020/02/26 11:29
 */
@Setter
@Getter
@Accessors(chain = true)
public class ISecurityUser implements UserDetails {

    private String userId;
    private String username;
    private String password;
    private Collection<? extends GrantedAuthority> authorities;

    public ISecurityUser(String userId, String username, String password, Collection<? extends GrantedAuthority> authorities) {
        this.userId = userId;
        this.username = username;
        this.password = password;
        this.authorities = authorities;
    }

    /**
     * 返回分配给用户的角色列表
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities  ;
    }

    /**
     * 账户是否未过期，过期无法验证
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 指定用户是否解锁，锁定的用户无法进行身份验证
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 指示是否已过期的用户的凭证（密码）,过期的凭据防止认证
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 是否可用，禁用的用户不用身份验证
     * @return
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}
